package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.TourCity;
import com.ruoyi.system.domain.vo.CityVo;
import com.ruoyi.system.service.ITourCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("city")
@ResponseBody
public class TourCityController extends BaseController {

    @Autowired
    private ITourCityService cityService;

    @GetMapping("/list")
    public AjaxResult list() {
        try {
            List<TourCity> cities = cityService.selectCityList();
            if(cities != null) {
                return AjaxResult.success(cities);
            }
            return AjaxResult.error("查询出错");
        } catch (Exception e) {
            e.printStackTrace();
            // 默认错误是500
            return AjaxResult.error("发生错误");
            // return error(AjaxResult.Type.WARN, "发生错误");
        }
    }

    @PostMapping("/detail")
    public AjaxResult detail(int cityId) {
        try {
            CityVo city = cityService.cityDetail(cityId);
            if (city != null) {
                return AjaxResult.success(city);
            }
            return AjaxResult.error("查询出错");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping("/details")
    public AjaxResult details(int cityId) {
        try {
            TourCity city = cityService.cityDetails(cityId);
            if (city != null) {
                return AjaxResult.success(city);
            }
            return AjaxResult.error("查询出错");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }


}
